#include <opencv2/features2d.hpp>

using namespace std;
using namespace cv;

// 拷贝KeyPoint内存
int memcpy_kp(char* buf, const vector<KeyPoint>& kp) {
    int len = 0;
    int size = kp.size();

    // 数组大小
    printf("kp数组大小 %d\n", size);
    memcpy(buf, &size, sizeof(int));
    len += sizeof(int);

    for (int i = 0; i < kp.size(); i++) {
        // pt
        memcpy(buf + len, &(kp[i].pt.x), sizeof(kp[i].pt.x));
        len += sizeof(kp[i].pt.x);

        memcpy(buf + len, &(kp[i].pt.y), sizeof(kp[i].pt.y));
        len += sizeof(kp[i].pt.y);
    }

    return len;
}

// 拷贝Mat内存
int memcpy_mat(char* buf, const Mat& m) {
    int len = 0;
    int elem_size = m.elemSize();
    int elem_type = m.type();

    memcpy(buf + len, &(m.cols), sizeof(int));
    len += sizeof(int);

    memcpy(buf + len, &(m.rows), sizeof(int));
    len += sizeof(int);

    memcpy(buf + len, &(elem_size), sizeof(int));
    len += sizeof(int);

    memcpy(buf + len, &(elem_type), sizeof(int));
    len += sizeof(int);

    const size_t data_size = m.cols * m.rows * elem_size;
    printf("mat 数组大小 %d\n", data_size);
    memcpy(buf + len, m.ptr(), data_size);
    len += data_size;

    return len;
}

